package com.woniu.smallmedical.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.smallmedical.entity.PageBean;
import com.woniu.smallmedical.entity.ResponseResult;
import com.woniu.smallmedical.entity.VregAndPat;
import com.woniu.smallmedical.server.VregAndPatServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class VregAndPatController {
    @Autowired
    VregAndPatServer vregAndPatServer;

    @GetMapping("/vregAndPats")
    public ResponseResult<PageBean<VregAndPat>> vregAndPats(VregAndPat vregAndPat,
                                                            int pageSize, int pageIndex) {
        System.out.println("参数===" + vregAndPat);
        System.out.println("pageSize：" + pageSize);
        System.out.println("pageIndex：" + pageIndex);
        List<VregAndPat> vregAndPats = vregAndPatServer.vregAndPats(vregAndPat, pageIndex, pageSize);
        System.out.println("查询结果====" + vregAndPats);

        PageInfo<VregAndPat> pageInfo = new PageInfo<>(vregAndPats);
        PageBean<VregAndPat> pageBean = new PageBean<>();
        pageBean.setPageBeanList(vregAndPats);
        pageBean.setPageIndex(pageInfo.getPageNum());
        pageBean.setPageSize(pageInfo.getPageSize());
        pageBean.setTotalRecord((int) (pageInfo.getTotal()));
        pageBean.setTotalPage(pageInfo.getPages());

        return new ResponseResult(pageBean, 200, "查询成功！");
    }

    @GetMapping("/vregAndPatByPaid/{paid}")
    public ResponseResult vregAndPatByPaid(@PathVariable int paid) {
        VregAndPat vregAndPat = vregAndPatServer.getVregAndPatByPaid(paid);
        return new ResponseResult(vregAndPat, 200, "患者视图信息！");
    }
}
